package pine.web.common.grid;

import java.util.List;

public class Pagination<T> {
	
	private static final int DEFAULT_PAGE = 1;
	private static int DEFAULT_PAGE_SIZE = 20;
	
	//需要显示的数据列表
	private List<T> rows;
	
	//记录总条数
	private long total;
	
	//每页显示数据条件
	private int pageSize = DEFAULT_PAGE_SIZE;
	
	//当前页码
	private int currentPage = DEFAULT_PAGE;
	
	public Pagination() {}
	
	public Pagination(int currentPage, int pageSize) {
		if (pageSize < 1) {
			throw new IllegalArgumentException("Count should be greater than zero!");
		}
		this.currentPage = currentPage;
		this.pageSize = pageSize;
	}
	
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}
	
	public void setRows(List<T> rows) {
		this.rows = rows;
	}
	
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	
	public void setTotal(long total) {
		this.total = total;
	}
	
	public int getCurrentPage() {
		return currentPage;
	}
	
	public int getCurrentPageStartIndex() {
		return (currentPage - 1) * pageSize;
	}
	
	public List<T> getRows() {
		return rows;
	}
	
	public int getPageSize() {
		return pageSize;
	}
	
	public long getTotal() {
		return total;
	}
}
